home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Arsenal Files 4
/
The Arsenal Files 4 (Arsenal Computer).ISO
/
casm
/
au116-as.exe
/
UTIL
/
LOG.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1994-12-13
|
2KB
|
73 lines
#include "..\au.hpp"
/*************************************************************************/
HANDLE *LOG::find(char *log_file)
{
for (int i=0; i<num_handles; i++)
{
if (stricmp(file_name[i], log_file) == 0)
return handle[i];
}
return NULL;
}
HANDLE *LOG::add(AU *au, char *log_file)
{
if (num_handles < MAX_LOGS)
{
handle[num_handles]->open(au, log_file,
O_CREAT|O_WRONLY|O_TEXT|O_APPEND);
file_name[num_handles] = new char[strlen(log_file)+1];
strcpy(file_name[num_handles], log_file);
num_handles++;
return handle[num_handles-1];
}
handle[MAX_LOGS-1]->close();
handle[MAX_LOGS-1]->open(au, log_file,
O_CREAT|O_WRONLY|O_TEXT|O_APPEND);
delete [] file_name[MAX_LOGS-1];
file_name[MAX_LOGS-1] = new char[strlen(log_file)+1];
strcpy(file_name[MAX_LOGS-1], log_file);
return handle[MAX_LOGS-1];
}
void LOG::write(AU *au, char *log_file, char *string)
{
HANDLE *handle;
if (log_file[0] == '\0')
return;
if ((handle = find(log_file)) == NULL)
{
if ((handle = add(au, log_file)) == NULL)
{
printf("Unable to log the message: \"%s\" to file %s\n", string, log_file);
if (!ask_continue())
exit(1);
}
}
handle->write_raw(string, strlen(string));
return;
}
LOG::LOG()
{
num_handles = 0;
for (int i=0; i<MAX_LOGS; i++)
handle[i] = new HANDLE(0);
}
LOG::~LOG()
{
int i;
for (i=0; i<MAX_LOGS; i++)
delete handle[i];
for (i=0; i < num_handles; i++)
delete [] file_name[i];
}